/* _NSDATA_C_
 * 
 * SOLVES THREE DIMENSIONAL, INCOMPRESSIBLE NAVIER-STOKES
 * EQUATION WITH RECTANGULAR DOMAIN USING FINITE DIFFERENCING 
 * ON A STAGGERED GRID
 * UTILIZES THE PROJECTION METHOD.  THE CONSERVATIVE FORM
 * CONVECTION IS DISCRETIZED WITHOUT THE USE OF UPWIND TREATMENT; 
 * BOTH THE ADVECTION AND DIFUSSION TERMS ARE TREATED EXPLICITLY. 
 * THE CURRENT SETUP IS FOR A LID DRIVEN CAVITY PROBLEM WITH A WELL
 * KNOWN VELOCITY AT THE TOP AND NO-SLIP BOUNDARY CONDIITIONS AT
 * ALL OTHER BOUNDARIES
 * 
 * ORIGINALLY WRITTEN BY DR. ZHI-GANG FENG: UNIVERSITY OF NORTH TEXAS
 * 
 * PORTED TO C AND 3D BY JOHN LEIDEL: GRADUATE STUDENT
 * 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
#include "nsproj.h"


#define NSALLOCBUF(x) x=(char *)malloc( 65536 );if(x==NULL){return -1;}
#define NSFREEBUF(x) if(x!=NULL){free(x);x=NULL;}

//---------------------------------------NSPROJ_WRITETECDATA
// NSPROJ_WRITETECDATA
// WRITES DATA IN TEC DATA FORMAT FOR PARSING IN TECPLOT
// EACH TIME STEP IS WRITTEN TO INDIVIDUAL FILE: 
//            "project.STEP"
// FORMAT : 
// PRE: MESH IS INITIALIZED
//      PROJECT IS NON NULL
//      TIME >= 0
// POST: DATA IS WRITTEN TO FILE
// RETURNS 0 ON SUCCESS, NONZERO OTHERWISE 
//----------------------------------------------------------
int nsproj_writetecdata( char *project, NSMESH mesh, int count )
{
    /* VARS */
    int i        = 0;
    int j        = 0;
    int k        = 0;
    double u0    = 0;
    double v0    = 0;
    double tm1   = 0.;
    double pr0   = 0;
    double psi0  = 0;
    double vor0  = 0;
    double uv    = 0;;
    FILE * ofile = NULL;
    char fname[64];
    /* ---- */

    sprintf( fname, "%s.%d", project,count );
    ofile = fopen( fname, "w" );

    fprintf(ofile,"VARIABLES=\"X\",\"Y\",\"Z\",\"U\",\"V\",\"W\",\"P\",\n");
  
    fprintf(ofile,"ZONE, I=%d, J=%d, K=%d, F=POINT\n", mesh.mx+1,mesh.my+1,mesh.mz+1);
  
    for( k=0; k<mesh.nz-1; k++ )
    {
	for( j=0; j<mesh.ny-1; j++ )
        {
	    for( i=0; i<mesh.nx-1; i++ )
            {
              
		/* PRINT CURRENT VALUES */
		/* FORMAT :: T  X  Y  Z  U  V  W  U*  V*  W* */
		fprintf(ofile,"%5d %5d %5d %8.4e %8.4e %8.4e %8.4e\n",
			i,j,k, 
			mesh.U[i][j][k], 
			mesh.V[i][j][k], 
			mesh.W[i][j][k], 
			mesh.P[i][j][k] ); 
            }
        }
    }
    fclose(ofile);

    return 0;
}


//---------------------------------------NSPROJ_WRITEDATA
// NSPROJ_WRITEDATA
// WRITES DATA IN CUSTOM NSPROJ FORMAT FOR PARSING
// ALL TIME STEPS ARE WRITTEN TO A SINGLE FILE "project.nsp"
// FORMAT:: TIME X Y Z U V W P"
// PRE: MESH IS INITIALIZED
//      PROJECT IS NON NULL
//      TIME >= 0
// POST: DATA IS WRITTEN TO FILE
// RETURNS 0 ON SUCCESS, NONZERO OTHERWISE
//-------------------------------------------------------
int nsproj_writedata( char *project, NSMESH mesh, double t )
{
    /* VARS */
    FILE *ofile = NULL;
    char fname[64];
    int i   = 0;
    int j   = 0;
    int k   = 0;
    /* ---- */

    /*-- PRINT VELOCITY */
    /* SETUP FILE NAME */
    sprintf( fname, "%s%s", project,".nsp" );

    ofile = fopen( fname, "a+" );

    if( ofile == NULL )
    {
	return -1;
    }
    
    fprintf( ofile, "%s\n", "# TIME  X  Y  Z  U   V   W   P" );
    fflush( ofile );
    for( i=1; i<mesh.nx-1; i++ )
    {
	for( j=1; j<mesh.ny-1; j++ )
	{
	    for( k=1; k<mesh.nz-1; k++ )
	    {
		/* PRINT CURRENT VALUES */
		/* FORMAT :: T  X  Y  Z  U  V  W  U*  V*  W* */
		fprintf( ofile, "%f\t%d\t%d\t%d\t%f\t%f\t%f\t%f\n", 
			 t,i,j,k,
			 mesh.U[i][j][k], 
			 mesh.V[i][j][k], 
			 mesh.W[i][j][k], 
			 mesh.P[i][j][k] ); 
		fflush( ofile );
	    }
	}
    }
      
    fprintf( ofile, "%s\n", "#END STEP" );
    fclose( ofile );
    ofile = NULL;
    memset( fname, 0, sizeof( fname ) );

    return 0;
}

//---------------------------------------NSPROJ_MESHFREE
// NSPROJ_MESHFREE
// FREES MEMORY ASSOCIATED WITH MESH
// PRE: MESH IS NOT NULL
// POST: ALL MEMORY IS DEALLOCATED
// RETURNS VOID
//------------------------------------------------------
void nsproj_meshfree( NSMESH *mesh )
{
    /* VARS */
    int i   = 0;
    int j   = 0;
    /* ---- */

    for( i=0; i<mesh->ny; i++ )
    {
	for( j=0; j<mesh->nz; j++ )
	{
	    
	    free( mesh->U[i][j] );
	    free( mesh->V[i][j] );
	    free( mesh->W[i][j] );
	    free( mesh->Ustar[i][j] );
	    free( mesh->Vstar[i][j] );
	    free( mesh->Wstar[i][j] );
	    free( mesh->P[i][j] );
	    free( mesh->Pnew[i][j] );
	    
	}
	free( mesh->U[i] );
	free( mesh->V[i] );
	free( mesh->W[i] );
	free( mesh->Ustar[i] );
	free( mesh->Vstar[i] );
	free( mesh->Wstar[i] );
	free( mesh->P[i] );
	free( mesh->Pnew[i] );
    }
    
    free( mesh->U );
    free( mesh->V );
    free( mesh->W );
    free( mesh->Ustar );
    free( mesh->Vstar );
    free( mesh->Wstar );
    free( mesh->P );
    free( mesh->Pnew );

    mesh->U     = NULL;
    mesh->V     = NULL;
    mesh->W     = NULL;
    mesh->Ustar = NULL;
    mesh->Vstar = NULL;
    mesh->Wstar = NULL;
    mesh->P     = NULL;
    mesh->Pnew  = NULL;
    
    return ;
}

//---------------------------------------NSPROJ_MESHINIT
// NSPROJ_MESHINIT
// INITIALIZES MESH ELEMENTS
// TOP [NORTH] FACE IS INITIALIZED TO `1`, 
// ALL OTHER FACES INITIALIZED TO ZERO
// INCLUDES INTIALIZATION OF GHOST CELLS
// PRE: MESH IS NON NULL
// POST: MESH IS INITIALIZED
// RETURNS 0 ON SUCCESS, NONZERO OTHERWISE
//------------------------------------------------------
int nsproj_meshinit( NSMESH *mesh )
{
    /* VARS */
    int i = 0;
    int j = 0;
    int k = 0;
    /* ---- */

    if( mesh == NULL )
    {
	return -1;
    }

    printf( "%s\n", "....INITIALIZING MESH ELEMENTS" );

    /* PRE-INIT EVERYTHING TO ZERO */
    for( i=0; i<mesh->nx; i++ )
    {
	for( j=0; j<mesh->ny; j++ )
	{
	    for( k=0; k<mesh->nz; k++ )
	    {
		mesh->U[i][j][k] = 0;
		mesh->V[i][j][k] = 0;
		mesh->W[i][j][k] = 0;
		mesh->P[i][j][k] = 0;
	    }
	}
    }
    
    /* WEST AND EAST FACE :: NO DELTA_X */
    for( j=0; j<mesh->ny; j++ )
    {
	for( k=0;k<mesh->nz; k++ )
	{
	    mesh->V[0][j][k] = mesh->vW;
	    mesh->V[mesh->nx-1][j][k] = mesh->vE;
	}
    }
    
    /* NORTH AND SOUTH FACE :: NO DELTA_Y */
    for( i=0; i<mesh->nx; i++ )
    {
	for( k=0; k<mesh->nz; k++ )
	{
	    mesh->U[i][0][k] = mesh->uS;
	    mesh->U[i][mesh->nx-1][k] = mesh->uN;
	}
    }

    /* FRONT AND BACK FACE :: NO DELTA_Z */
    for( i=0; i<mesh->nx; i++ )
    {
	for( j=0; j<mesh->ny; j++ )
	{
	    mesh->W[i][j][0] = mesh->wF;
	    mesh->W[i][j][mesh->nz-1] = mesh->wB;
	}
    }
    
    return 0;
}

//---------------------------------------NSPROJ_MESHALLOC
// NSPROJ_MESHALLOC
// ALLOCATES MESH WITH MX+2 * MY+2 * MZ+2 ELEMENTS
// ALSO SETS `NX`; `NY`; `NZ` 
// PRE: MX, MY, MZ ARE > 0 < MAX
// POST: MESH IS ALLOCATED
// RETURNS 0 ON SUCCESS, NONZERO OTHERWISE
//-------------------------------------------------------
int nsproj_meshalloc( NSMESH *mesh )
{
    /* VARS */
    double ngrid  = 0;
    int i      = 0;
    int j      = 0;
    /* ----- */

    /* SANITY CHECK */
    if( (mesh->mx < 1) || 
	(mesh->my < 1) || 
	(mesh->mz < 1) || 
	(mesh->mx > _MAX_X_) || 
	(mesh->my > _MAX_Y_) || 
	(mesh->mz > _MAX_Z_))
    {
	return -1;
    }
    /* DONE */

    /* SETUP NUM GRIDPOINTS */
    /* NOTE :: EVERY AXIS HAS A GHOST CELL ON EVERY EDGE; 
     * HENCE `num_grid_points = num_segments +2` */
    mesh->nx = mesh->mx+2;
    mesh->ny = mesh->my+2;
    mesh->nz = mesh->mz+2;

    printf( "%s%d%s%d%s%d\n", "....GRID POINT DIMENSIONS W/ GHOST CELLS : ", mesh->nx, " X ", mesh->ny, " X ", mesh->nz );

    ngrid = sizeof( double ) * mesh->nx * mesh->ny * mesh->nz;

    /* ALLOCATE MEMORY */

    /*-- U */
    mesh->U = (double ***)malloc( mesh->nx * sizeof (double ***) );
    for( i=0; i<mesh->ny; i++ )
    {
	mesh->U[i] = (double **)malloc( mesh->ny * sizeof( double ** ) );
	for( j=0; j<mesh->nz; j++ )
	{
	    mesh->U[i][j] = (double *)malloc( mesh->nz * sizeof( double * ) );
	}
    }
    /*-- V */
    mesh->V = (double ***)malloc( mesh->nx * sizeof (double ***) );
    for( i=0; i<mesh->ny; i++ )
    {
	mesh->V[i] = (double **)malloc( mesh->ny * sizeof( double ** ) );
	for( j=0; j<mesh->nz; j++ )
	{
	    mesh->V[i][j] = (double *)malloc( mesh->nz * sizeof( double * ) );
	}
    }

    /*-- W */
    mesh->W = (double ***)malloc( mesh->nx * sizeof (double ***) );
    for( i=0; i<mesh->ny; i++ )
    {
	mesh->W[i] = (double **)malloc( mesh->ny * sizeof( double ** ) );
	for( j=0; j<mesh->nz; j++ )
	{
	    mesh->W[i][j] = (double *)malloc( mesh->nz * sizeof( double * ) );
	}
    }

    /*-- Ustar */
    mesh->Ustar = (double ***)malloc( mesh->nx * sizeof (double ***) );
    for( i=0; i<mesh->ny; i++ )
    {
	mesh->Ustar[i] = (double **)malloc( mesh->ny * sizeof( double ** ) );
	for( j=0; j<mesh->nz; j++ )
	{
	    mesh->Ustar[i][j] = (double *)malloc( mesh->nz * sizeof( double * ) );
	}
    }

    /*-- Vstar */
    mesh->Vstar = (double ***)malloc( mesh->nx * sizeof (double ***) );
    for( i=0; i<mesh->ny; i++ )
    {
	mesh->Vstar[i] = (double **)malloc( mesh->ny * sizeof( double ** ) );
	for( j=0; j<mesh->nz; j++ )
	{
	    mesh->Vstar[i][j] = (double *)malloc( mesh->nz * sizeof( double * ) );
	}
    }

    /*-- Wstar */
    mesh->Wstar = (double ***)malloc( mesh->nx * sizeof (double ***) );
    for( i=0; i<mesh->ny; i++ )
    {
	mesh->Wstar[i] = (double **)malloc( mesh->ny * sizeof( double ** ) );
	for( j=0; j<mesh->nz; j++ )
	{
	    mesh->Wstar[i][j] = (double *)malloc( mesh->nz * sizeof( double * ) );
	}
    }

    /*-- P */
    mesh->P = (double ***)malloc( mesh->nx * sizeof (double ***) );
    for( i=0; i<mesh->ny; i++ )
    {
	mesh->P[i] = (double **)malloc( mesh->ny * sizeof( double ** ) );
	for( j=0; j<mesh->nz; j++ )
	{
	    mesh->P[i][j] = (double *)malloc( mesh->nz * sizeof( double * ) );
	}
    }
    
    /*-- Pnew */
    mesh->Pnew = (double ***)malloc( mesh->nx * sizeof (double ***) );
    for( i=0; i<mesh->ny; i++ )
    {
	mesh->Pnew[i] = (double **)malloc( mesh->ny * sizeof( double ** ) );
	for( j=0; j<mesh->nz; j++ )
	{
	    mesh->Pnew[i][j] = (double *)malloc( mesh->nz * sizeof( double * ) );
	}
    }

    /* SANITY CHECK THE MEMORY */
    if( (mesh->U     == NULL) || 
	(mesh->V     == NULL) || 
	(mesh->W     == NULL) ||
	(mesh->Ustar == NULL) || 
	(mesh->Vstar == NULL) || 
	(mesh->Wstar == NULL) || 
	(mesh->P     == NULL) || 
	(mesh->Pnew  == NULL))
    {
	nsproj_meshfree( mesh );
	return -1;
    }

    printf( "%s%f%s\n", "....ALLOCATED ", 
	    ngrid*8,
	    " BYTES OF MEMORY" );

    return 0;
}

//---------------------------------------NSPROJ_REMOVENL
// NSPROJ_REMOVENL
// REMOVES NEWLINE CHARACTERS FROM STRINGS
//------------------------------------------------------
void nsproj_removenl( char *value )
{
    /* VARS */
    char tmp[64];
    /* ---- */

    if( strlen( value ) <= 1 )
    {
	return ;
    }

    value[strlen(value)-1] = '\0';

    memset( tmp, 0, sizeof( tmp ) );
    
    /* COPY TO TEMP SPACE */
    strncpy( tmp, value, strlen( value ) );
    
    /* COPY NEW STRING BACK TO PERM SPACE MINUS THE NEWLINE[LAST CHARACTER] */
    memset( value, 0, sizeof( value ) );
    strncpy( value, tmp, strlen( tmp )-2 );

    return ;
}

//---------------------------------------NSPROJ_READDATEFILE
// NSPROJ_READDATAFILE
// READS DATAFILE SPECIFIED BY `datafile`
// POPULATES ALL NECESSARY ELEMENTS
// RETURNS 0 ON SUCCESS, NONZERO OTHERWISE
//----------------------------------------------------------
int nsproj_readdatafile( char *datafile, 
			 double *Re, 
			 double *dt, 
			 double *tf, 
			 double *lx, 
			 double *ly, 
			 double *lz, 
			 double *uN,
			 double *uS,
			 double *vE,
			 double *vW,
			 double *wF,
			 double *wB,
			 int *mx, 
			 int *my, 
			 int *mz,
			 int *nsp,
			 int *tec,
			 char *proj )
{
    /* VARS */
    FILE *infile = NULL;
    char buffer[1024];
    char tmpc[1024];
    char p0[1024];
    char p1[10];
    char p2[10];
    float tmpd  = 0;
    int tmpi     = 0;
    /* ---- */

    /* INIT BOUNDARY CONDITIONS JUST IN CASE */
    *Re=100;
    *dt=0.001;
    *tf=0.1;
    *lx=1.;
    *ly=1.;
    *lz=1.;
    *mx=20;
    *my=20;
    *mz=20;
    *uN = 1;
    *uS = 0;
    *vE = 0;
    *vW = 0;
    *wF = 0;
    *wB = 0;
    *tec = 1;
    *nsp = 1;

    if( datafile == NULL )
    {
	return -1;
    }

    /* OPEN DATA FILE */
    infile = fopen( datafile, "r" );
    if( infile == NULL )
    {
	return -1;
    }

    /* BEGIN SEARCHING FILE */
    printf( "%s\n", "....INTERPRETING CONFIGURATION FILE" );

    while( !feof(infile) )
    {
	memset( buffer, 0, sizeof( buffer ));

	fgets( buffer, sizeof( buffer ), infile );
	
	if( (buffer[0] != '#' ) && (strlen(buffer)>4) )
	{
	    if( strstr( buffer, "PROJECT") != NULL )
	    {		
		sprintf( tmpc, "%s", strstr( buffer, "PROJECT" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%s", p1, p2, proj );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "REYNOLDS") != NULL )
	    {	
		sprintf( tmpc, "%s", strstr( buffer, "REYNOLDS" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*Re = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "DELTA_T") != NULL )
	    {		
		sprintf( tmpc, "%s", strstr( buffer, "DELTA_T" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*dt = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "FINAL_T") != NULL )
	    {		
		sprintf( tmpc, "%s", strstr( buffer, "FINAL_T" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*tf = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "LEN_X") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "LEN_X" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*lx = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "LEN_Y") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "LEN_Y" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*ly = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "LEN_Z") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "LEN_Z" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*lz = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "SEG_X") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "SEG_X" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%d", p1, p2, &tmpi );
		*mx = tmpi;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "SEG_Y") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "SEG_Y" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%d", p1, p2, &tmpi );
		*my = tmpi;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "SEG_Z") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "SEG_Z" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%d", p1, p2, &tmpi );
		*mz = tmpi;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "NSP_FILE") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "NSP_FILE" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%d", p1, p2, &tmpi );
		*nsp = tmpi;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "TEC_FILE") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "TEC_FILE" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%d", p1, p2, &tmpi );
		*tec = tmpi;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "U_NORTH") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "U_NORTH" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*uN = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "U_SOUTH") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "U_SOUTH" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*uS = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "V_EAST") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "V_EAST" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*vE = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "V_WEST") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "V_WEST" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*vW = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "W_FRONT") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "W_FRONT" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*wF = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	    else if( strstr( buffer, "W_BACK") != NULL )
	    {
		sprintf( tmpc, "%s", strstr( buffer, "W_BACK" ) );
		nsproj_removenl( tmpc );
		sscanf( tmpc, "%s%s%f", p1, p2, &tmpd );
		*wB = tmpd;
		memset( p0, 0, sizeof( p0 ) );
		memset( tmpc, 0, sizeof( tmpc ));
	    }
	}
	
	memset( buffer, 0, sizeof( buffer ) );
    }

    memset( buffer, 0, sizeof( buffer ) );
    /* CLOSE DATA FILE */
    fclose( infile );

    /* PRINT RESULTS OF CONFIG READ */
    printf( "%s\n", "---------------------------------------" );
    printf( "%s%s\n", "PROJECT:         ", proj );
    printf( "%s%f\n", "REYNOLDS NUMBER: ", *Re );
    printf( "%s%f\n", "DELTA_T:         ", *dt );
    printf( "%s%f\n", "FINAL_T:         ", *tf ); 
    printf( "%s%f\n", "LENGTH_X:        ", *lx );
    printf( "%s%f\n", "LENGTH_Y:        ", *ly );
    printf( "%s%f\n", "LENGTH_Z:        ", *lz );
    printf( "%s%d\n", "SEGS_X:          ", *mx );
    printf( "%s%d\n", "SEGS_Y:          ", *my );
    printf( "%s%d\n", "SEGS_Z:          ", *mz ); 
    printf( "%s%f\n", "uN:              ", *uN );
    printf( "%s%f\n", "uS:              ", *uS );
    printf( "%s%f\n", "vE:              ", *vE );
    printf( "%s%f\n", "vW:              ", *vW );
    printf( "%s%f\n", "wF:              ", *wF );
    printf( "%s%f\n", "wB:              ", *wB );
    printf( "%s\n", "---------------------------------------" );
    /* DONE */

    return 0;
}

/* EOF */
